package com.allianz.webapps.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.webapps.common.CustomerContextHolder;
import com.allianz.webapps.dbpojo.AdT13AppMessages;
import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.https.interfaces.util.ObjectUtil;
import com.allianz.webapps.service.AdT13AppMessagesService;
import com.fasterxml.jackson.databind.ObjectMapper;

@Controller
@RequestMapping(value="index")
public class IndexController {
	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private ObjectUtil objectUtil;
	
	@RequestMapping(value="index")
	public String index(HttpServletRequest request,HttpServletResponse response){
		
		return "views/page/index";
	}
	@RequestMapping(value="/toUpload")
	public String toUpload(){
		return "views/page/upload";
	}
	@RequestMapping(value="certificate")
	public String to(HttpServletRequest request,HttpServletResponse response){
		return "views/page/certificate";
	}
	@RequestMapping(value="changePassword")
	@ResponseBody
	public String changePassword(HttpServletRequest request,HttpServletResponse response)
			throws Exception{
	    String cp = request.getParameter("jsonParam");
		User obj =objectMapper.readValue(cp,User.class);
		User user = (User) request.getSession().getAttribute("username");
		user.setPassword(obj.getPassword());
		user.setOldPassword(obj.getOldPassword());
		String body=objectUtil.requestParam(user, "user.changePwd");		
		return body;
	}

}